﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <script>
        let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
        console.log("Array copyWithin(target_number, start_number, end?_number):拷贝同等长度的数组,会改变原数组");
        console.log(arr.copyWithin(arr.length * 2, 0, arr.length - 1).join("|"));
        console.log(arr.copyWithin(5, 0, 3).join("|"));
    </script>


    <script>
        let arr1 = [1, 2, 3];
        let arr2 = [4, 5, 6];
        let arr3 = [7, 8, 9];
        console.log("Array concat(...items):合并多个数组");
        console.log(arr1.concat(arr2, arr3).join("|"))
    </script>

    <script>
        let arrEntries = new Array("A", "B", "C", "D");
        let itrator = arrEntries.entries();
        let entries = [];
        for (let item of itrator) {
            entries.push(item);
        }
        console.log("IterableIterator<[number, T]> entries():将数组转换为遍历器,通过索引来访问每一项的值,如 item[0]-->代表索引 item[1]-->代表值");
        console.log(JSON.stringify(entries));
    </script>

    <script>
        console.log("boolean every((value_T, index_number, array_T[]) => boolean):判断每一项是否都满足条件,不满足将退出循环并返回false");
        let arrEvery = new Array(1, 2, 3, 4, 5, 6, 7, 8, 9);
        let times = 0;
        let b = arrEvery.every((value, index, array) => {
            times += 1;
            return true;
        });
        console.log("结果返回true调用次数:", times);
        times = 0;
        b = arrEvery.every((value, index, array) => {
            times += 1;
            return false;
        });
        console.log("结果返回false调用次数:", times);
    </script>

    <script>
        console.log("Array<T> fill(value: T, start?: number, end?: number):使用某个值来替换原数组中的值,并返回替换后的数组");
        let arrFill = new Array(1, 2, 3, 4, 5, 6, 7, 8, 9);
        arrFill.fill(100, 0, arrFill.length - 1);
        console.log(arrFill.join("|"));
    </script>

    <script>
        console.log("T[] filter(callbackfn: (value: T, index: number, array: ReadonlyArray<T>) => any, thisArg?: any):筛选复合条件的元素");
        let arrFilter = new Array(1, 2, 3, 4, 5, 6, 7, 8, 9);
        let filter = arrFilter.filter((value, index, array) => {
            if (value % 3 == 0) {
                return value;
            }
        });
        console.log(filter.join("|"));
    </script>

    <script>
        console.log("T find(predicate: (value: T, index: number, obj: T[]) => boolean, thisArg?: any):查找序列中第一个复合条件的元素,可能会出现找不到的情况");
        let arrfind = new Array(7, 8, 9, 10, 11, 12);
        let find = arrfind.find((value, index, array) => {
            return value % 3 == 0;
        });
        console.log(find);
        find = arrfind.find((value, index, array) => {
            if (value % 3 == 0) {
                return value;
            }
        });
        console.log(find);
    </script>

    <script>
        console.log("number findIndex(predicate: (value: T, index: number, obj: T[]) => boolean, thisArg?: any):查找第一个符合条件的元素的下标");
        let arrfindIndex = new Array(7, 8, 9, 10, 11, 12);
        let findIndex = arrfindIndex.findIndex((value, index, array) => {
            return value % 3 == 0;
        });
        console.log(findIndex);
    </script>

    <script>
        console.log("void forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any):");
        console.log("略");
    </script>

    <script>
        console.log("number indexOf(searchElement: T, fromIndex?: number):");
        console.log("略");
    </script>

    <script>
        console.log("string join(separator?: string):");
        console.log("略");
    </script>
    <script>
        console.log("IterableIterator<number> keys():");
        console.log("IterableIterator<T> values():");
        let arr_Key_Value = new Array("7", "8", "9", "10", "11", "12");
        let keys = arr_Key_Value.keys();
        let values = arr_Key_Value.values();
        let dicKey = [];
        for (let item of keys) {
            dicKey.push(item);
        }
        console.log(dicKey.join('|'));

        let dicValue = [];
        for (let item of values) {
            dicValue.push(item);
        }
        console.log(dicValue.join('|'));
    </script>

    <script>
        console.log("number lastIndexOf(searchElement: T, fromIndex?: number):取最后一个符合的元素的下标");
        let lastIndexOf = new Array(7, 8, 9, 9, 9, 12);
        //console.log(lastIndexOf.lastIndexOf(9));
        console.log("略");
    </script>

    <script>
        console.log("U[] map<U>(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any):遍历每一项,并返回自定义类型的数组");
        let arrMap = new Array(7, 8, 9, 9, 9, 12);
        let newMapArray = arrMap.map((value, index, array) => {
            return { key: value };
        });
        console.log(JSON.stringify(newMapArray));
    </script>

    <script>
        console.log("T | undefined pop(): 移除数组最后一个元素,并返回该元素");
        let pop = new Array(7, 8, 9, 10, 11, 12);
        console.log(pop.pop());
        console.log(pop.join("|"));
    </script>

    <script>
        console.log("number push(...items: T[]):向数组中追加元素,并返回数组容量");
        let push = new Array("7", "8", "9");
        console.log(push.push(new Array("10", "11", "12"), "13", "15", "14"));
        console.log(JSON.stringify(push));
    </script>

    <script>
        console.log("T reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T):");
        console.log("T reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T):");
        console.log("U reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U):");
        let reduce = new Array(1, 2, 3, 4, 5);
        console.log("总和:",
            reduce.reduce((pre, curr, currIndex, array) => {
                return pre + curr;
            })
        );
    </script>

    <script>
        console.log("T reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T):");
        console.log("T reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T):");
        console.log("U reduceRight<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U):");
        let reduceRight = new Array(1, 2, 3, 4, 5);
        console.log("总和:",
            reduceRight.reduceRight((pre, curr, currIndex, array) => {
                return pre + curr;
            })
        );
    </script>

    <script>
        console.log("T[] reverse():反转原数组,并返回反转后的数组");
        let reverse = new Array(1, 2, 3, 4, 5);
        let reverseContainer = [
			JSON.stringify(reverse),
			"|||",
			JSON.stringify(reverse.reverse()),
			"|||",
			JSON.stringify(reverse)];
        console.log(JSON.stringify(reverseContainer));
    </script>

    <script>
        console.log("shift(): T | undefined:移除数组中第一个元素并返回该元素");
        let shift = new Array(1, 2, 3, 4, 5);
        let shiftSson = JSON.stringify(shift);
        console.log(shiftSson, shift.shift(), JSON.stringify(shift));
    </script>

    <script>
        console.log("T[] slice(start?: number, end?: number):选择指定范围内的元素");
        let slice = new Array(1, 2, 3, 4, 5);
        console.log(slice, shift.slice(2, slice.length - 1));
    </script>

    <script>
        console.log("boolean some(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any):至少有一个满足条件将返回true,并结束遍历");
        let some = new Array(1, 2, 3, 4, 5);
        times = 0;
        console.log(some.some((value, index, array) => {
            times++;
            return true;
        }));
        console.log("结果返回true调用次数:", times);
        times = 0;
        console.log(some.some((value, index, array) => {
            times++;
            return false;
        }));
        console.log("结果返回false调用次数:", times);
    </script>

    <script>
        console.log("sort(compareFn?: (a: T, b: T) => number): this; 对原数组进行排序,并返回排序后的数组");
        let sort = new Array(1, 2, 3, 4, 5);
        console.log(JSON.stringify(sort.sort()));
        console.log(JSON.stringify(sort.sort((left, right) => {
            return left > right ? -1 : 1;
        })));
    </script>

    <script>
        console.log("splice(start: number, deleteCount?: number): T[]:移除原数组中指定范围的元素,并返回他们");
        console.log("splice(start: number, deleteCount: number, ...items: T[]): T[]:移除原数组中指定范围的元素,并返回他们同时在移除的位置插入元素");
        let splice = new Array(1, 2, 3, 4, 5);
        console.log(JSON.stringify(splice.splice(0, 2)));
        console.log(JSON.stringify(splice));
        console.log(JSON.stringify(splice.splice(0, 3, 11, 12, 13, 14, 15, 16)));
        console.log(JSON.stringify(splice));
    </script>

    <script>
        console.log("string toLocaleString():类似于arr.join(',')");
        let toLocaleString = new Array(1, 2, 3, 4, 5);
        console.log(toLocaleString.toLocaleString());
    </script>

    <script>
        console.log("string toString():类似于arr.join(',')");
        let _toString = new Array(1, 2, 3, 4, 5);
        console.log(_toString.toString());
    </script>

    <script>
        console.log("number unshift(...items: T[]):在原数组开头插入元素,并返回数组当前容量");
        let unshift = new Array(1, 2, 3, 4, 5);
        console.log(unshift.unshift(6, 7, 8, 9), unshift.toString());
    </script>
</head>
<body>

</body>
</html>